package net.lzzy.practicesapi1;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @author locker
 */
@Component
public class PracticesMvcConfigure implements WebMvcConfigurer {
    @Value("${user.pic}")
    private String path;
    @Value("${pic.size}")
    private int maxPicSize;
    @Value("${pic.per.size}")
    private int maxPerSize;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("file:/" + path,
                        "classpath:/static/",
                        "classpath:/public/",
                        "classpath:/webapp/");
    }

    @Bean
    public CommonsMultipartResolver multipartResolver(){
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setMaxUploadSize(maxPicSize);
        //resolver.setMaxUploadSizePerFile(maxPerSize);
        return resolver;
    }
}
